package com.by.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
* 解决跨域问题
* */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /*
    * 处理跨域请求
    * */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//拦截所有请求
                .allowCredentials(false)//不允许携带cookie
                .allowedHeaders("*")//允许所有的请求头
                .allowedOrigins("*")//允许来自所有的域名访问
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")//允许哪些请求跨域
                .maxAge(36000);//预检缓存时间
    }
}
